package com.tydic.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tydic.system.domain.SysDictData;
import com.tydic.system.domain.vo.TreeDataVo;
import com.tydic.system.mapper.SysDictDataMapper;
import com.tydic.system.service.ISysDictDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 字典 业务层处理
 *
 * @author Lion Li
 */
@RequiredArgsConstructor
@Service
public class SysDictDataServiceImpl implements ISysDictDataService {

    private final SysDictDataMapper baseMapper;


    @Override
    public List<TreeDataVo> treeData(String dictType) {
        LambdaQueryWrapper<SysDictData> lqw = Wrappers.lambdaQuery(SysDictData.class);
        lqw.eq(SysDictData::getDictType, dictType);
        lqw.orderByAsc(SysDictData::getTreeSort);
        return baseMapper.selectList(lqw).stream().map(item -> {
            TreeDataVo vo = new TreeDataVo();
            vo.setId(item.getDictCode());
            vo.setName(item.getDictLabel());
            vo.setValue(item.getDictValue());
            return vo;
        }).collect(Collectors.toList());
    }
}
